﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NF_Mode;
using System.Collections;
using NF_Base;
using System.Threading.Tasks;
using System.Diagnostics;
using NF_Bll;

namespace NF_Web
{
    public partial class FrmLogin : FrmBase
    {
        public FrmLogin()
        {
            InitializeComponent();

            
            this.ShowInTaskbar = true;
            Control.CheckForIllegalCrossThreadCalls = false;
            this.Text = "用户登录";
            lblcopy.Text = "西安仙侗科技有限公司(C)2014-2017  v" + Application.ProductVersion.ToString();
        }

        /// <summary>
        /// LODE
        /// </summary>
        private void FrmLogin_Load(object sender, EventArgs e)
        {

            #region - 初始化系统配置 -

            BaseClass.ServerConnection = INIOperationClass.INIGetStringValue(Application.StartupPath + @"\System.ini", "server", "url", "");

            #endregion




        }


        /// <summary>
        /// 登陆
        /// </summary>
        private void btnLogin_Click(object sender, EventArgs e)
        {
            UserLogin();
        }


        /// <summary>
        /// 按下回车
        /// </summary>
        private void txtUserName_KeyDown(object sender, KeyEventArgs e)
        {
            if(e.KeyCode == Keys.Enter)
                UserLogin();
            
        }



        /// <summary>
        /// 注册
        /// </summary>
        private void lblregister_Click(object sender, EventArgs e)
        {

        }




        #region - 公共方法 -


        public void UserLogin()
        {
            //验证
            if (string.IsNullOrEmpty(this.txtUserName.Text.Trim()))
            {
                MessageBoxShow.Alert("请输入用户名！"); return;
            }

            if (string.IsNullOrEmpty(this.txtUserPass.Text.Trim()))
            {
                MessageBoxShow.Alert("请输入密码！"); return;
            }
                

            //远程校验
            SysUser sysus = new SysUser() { us_UserName = txtUserName.Text.Trim(), us_Password = txtUserPass.Text.Trim() };
            BaseAnswer bar = new BaseAnswer();
            UserLogin_Bll<dynamic>.LoginByPassword(sysus, ref bar);

            //结果
            if (bar.AnswerType == BaseAnswer.Answers.Succee)
                this.DialogResult = System.Windows.Forms.DialogResult.OK;
            else
                MessageBoxShow.Alert(bar.AnswerMeg);

            
        }

        #endregion








    }
}
